﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace caufingHealth.Forms
{
    public partial class SearchForm : Form
    {
        private String[] modesList = new String[] { "DOB","First and Last Name","Last Name and DOB" };
        public enum SEARCH_MODES {DOB, FIRST_AND_LAST, LAST_AND_DOB};

        private SearchMode[] modes = new SearchMode[] { new SearchMode("DOB", SEARCH_MODES.DOB),
                                                        new SearchMode("First and Last Name", SEARCH_MODES.FIRST_AND_LAST),
                                                        new SearchMode("Last Name and DOB", SEARCH_MODES.LAST_AND_DOB) };

        public SEARCH_MODES CurrentMode { get; private set; }
        public string FirstName { get; private set; }
        public string LastName { get; private set; }
        public DateTime DateOfBirth { get; private set; }

        public SearchForm()
        {
            InitializeComponent();
            this.ResizeRedraw = true;

            pnl_PatientName.Visible = false;
            pnl_DOB.Visible = false;
            this.Height -= (pnl_PatientName.Height + pnl_DOB.Height);

            dtp_DOB.CustomFormat = "MM'/'dd'/'yyyy";
            dtp_DOB.Format = DateTimePickerFormat.Custom;
            dtp_DOB.MaxDate = DateTime.Now;
            
            cb_SearchMode.DisplayMember = "Name";
            cb_SearchMode.ValueMember = "Value";
            cb_SearchMode.DataSource = modes;
        }

        private void pnl_PatientRecord_Paint(object sender, PaintEventArgs e)
        {

        }

        private void lbl_FirstName_Click(object sender, EventArgs e)
        {

        }

        private void cb_SearchMode_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentMode = (SEARCH_MODES)((ComboBox)sender).SelectedValue;
            switch (CurrentMode)
            {
                case SEARCH_MODES.DOB:
                    pnl_DOB.Visible = true;
                    pnl_PatientName.Visible = false;
                    break;
                case SEARCH_MODES.FIRST_AND_LAST:
                    pnl_PatientName.Visible = true;
                    txt_FirstName.Enabled = true;
                    pnl_DOB.Visible = false;
                    break;
                case SEARCH_MODES.LAST_AND_DOB:
                    pnl_PatientName.Visible = true;
                    pnl_DOB.Visible = true;
                    txt_FirstName.Enabled = false;
                    break;
            }
            
        }

        private class SearchMode
        {
            public string Name { get; private set; }
            public SEARCH_MODES Value { get; private set; }

            public SearchMode(string _name, SEARCH_MODES _value)
            {
                Name = _name;
                Value = _value;
            }

            public string toString()
            {
                return Name;
            }
        }

        private void btn_Search_Click(object sender, EventArgs e)
        {
            switch (CurrentMode)
            {
                case SEARCH_MODES.DOB:
                    DateOfBirth = dtp_DOB.Value;
                    break;
                case SEARCH_MODES.FIRST_AND_LAST:
                    FirstName = ((TextBox)txt_FirstName).Text;
                    LastName = ((TextBox)txt_LastName).Text;
                    break;
                case SEARCH_MODES.LAST_AND_DOB:
                    DateOfBirth = dtp_DOB.Value.Date;
                    LastName = ((TextBox)txt_LastName).Text;
                    break;
            }
        }

        private void dtp_DOB_ValueChanged(object sender, EventArgs e)
        {
            long date = (((DateTimePicker)sender).Value).Date.Ticks;
            long bob = new long();
        }
    }
}
